package com.example.demo.controller;


import com.example.demo.config.PageUtils;
import com.example.demo.entity.SysRole;
import com.example.demo.service.ISysRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author xsl
 * @since 2021-12-27
 */
@RestController
@CrossOrigin
@RequestMapping("/sys-role")
public class SysRoleController {

    @Resource
    ISysRoleService iSysRoleService;

    /*@GetMapping("listRole")//前台传的page、limit为string类型
    public PageUtils listRole(@RequestBody Map<String, Object> params){

        System.out.println(params);
        PageUtils pageUtils = iSysRoleService.queryPage(params);

        for (Object role : pageUtils.getList()
             ) {
            System.out.println(role);
        }

        return pageUtils;
    }*/

    @GetMapping("listRole")
    public PageInfo<SysRole> listRole(@RequestBody Map<String, Object> params){

        System.out.println(params);

        Integer pageNum = (Integer) params.get("page");
        Integer pageSize = (Integer) params.get("limit");


        PageHelper.startPage(pageNum,pageSize);
        List<SysRole> list = iSysRoleService.list();
        PageInfo<SysRole> page = new PageInfo<>(list);

        for (Object role : page.getList()
        ) {
            System.err.println(role);
        }

        return page;
    }
}
